package servlet;

import bean.Attence;
import utils.DBUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/list")
public class ListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ArrayList<Attence> list = new ArrayList<>();
        //处理乱码问题
        request.setCharacterEncoding("utf-8");
        //编写sql语句
        String sql ="select * from attence a ,student s where a.sid=s.sid";
        ResultSet rs = DBUtil.query(sql);
        try {
            while (rs.next()){
                int aid = rs.getInt("aid");
                String time = rs.getString("time");
                int type = rs.getInt("type");
                int sid = rs.getInt("sid");
                String sname = rs.getString("sname");
                Attence stu = new Attence(aid, time, type, sid, sname);
                list.add(stu);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        request.setAttribute("list",list);
        request.getRequestDispatcher("/WEB-INF/list.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


    }
}
